/*
 * testFramework.h
 *
 * Created: 2015-01-06 12:08:34
 *  Author: Andreas Domfors
 */ 


#ifndef TESTFRAMEWORK_H_
#define TESTFRAMEWORK_H_

#define length(x) sizeof(x) / sizeof(x[0])

typedef void (*testFunction) (void);
typedef struct {
	const char *name;
	testFunction func;
	} TestEntry ;

#define ENTRY(x) {#x, x}

void performTests(TestEntry *entries, int count);

#define DEFAULT_STACK_SIZE 0x1000

extern int taskResults[5];
void resetTest(void);

void reportAllStackUsage(void);

void schedulerStopper(void);

#define TEXTCOLOR_GREEN "\x1B[32m"
#define TEXTCOLOR_RED "\x1B[31m"
#define TEXTCOLOR_RESET "\x1B[0m"

extern int totalNumberOfTestCases, successfulTests, failedTests;

#define testIntEq(exp, val) do { totalNumberOfTestCases++;\
	if((val) != (exp)) { failedTests++;\
		ee_printf(TEXTCOLOR_RED "Test failed" TEXTCOLOR_RESET " (%s:%d) - " #exp " != %d (actual value: %d)\n", __FILE__, __LINE__, val, (exp)); }\
	else { successfulTests++; \
		ee_printf(TEXTCOLOR_GREEN "Test passed" TEXTCOLOR_RESET " (%s:%d): " #exp " == %d\n", __FILE__, __LINE__, val); } } while(0);

#define testBool(exp) do { totalNumberOfTestCases++; \
	if(!(exp)) { failedTests++; \
		ee_printf(TEXTCOLOR_RED "Test failed" TEXTCOLOR_RESET " (%s:%d) - " #exp " false \n", __FILE__, __LINE__); } \
	else { successfulTests++; \
		ee_printf(TEXTCOLOR_GREEN "Test passed" TEXTCOLOR_RESET " (%s:%d): " #exp "\n", __FILE__, __LINE__); } } while(0);

#endif /* TESTFRAMEWORK_H_ */